﻿<template>
    <div class="SHZY-common-layout">
        <div class="SHZY-common-layout-center">
            <el-row class="SHZY-common-search-box" :gutter="16">
                <el-form @submit.native.prevent="">
                    <el-col :span="6">
                        <el-form-item label="编码">
                            <el-input v-model="query.enCode" placeholder="编码" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="描述">
                            <el-input v-model="query.fullName" placeholder="描述" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="状态">
                            <el-select v-model='query.status' placeholder='状态' clearable>
                                <el-option key="1" label="处理中" value="-1"></el-option>
                                <el-option key="2" label="待处理" value="0"></el-option>
                                <el-option key="3" label="处理成功" value="1"></el-option>
                                <el-option key="4" label="处理异常" value="2"></el-option>
                                <el-option key="5" label="已关闭" value="3"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <template v-if="showAll">
                        <el-col :span="6">
                            <el-form-item label="创建时间">
                                <el-date-picker v-model="query.creatorTime" type="datetimerange" start-placeholder="开始日期"
                                    end-placeholder="结束日期" value-format="timestamp" clearable :editable="false" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="执行接口调用时间">
                                <el-date-picker v-model="query.execEndTime" type="datetimerange" start-placeholder="开始日期"
                                    end-placeholder="结束日期" value-format="timestamp" clearable :editable="false" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="发送接口调用时间">
                                <el-date-picker v-model="query.sendStartTime" type="datetimerange" start-placeholder="开始日期"
                                    end-placeholder="结束日期" value-format="timestamp" clearable :editable="false" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="进入处理函数时间">
                                <el-date-picker v-model="query.startTime" type="datetimerange" start-placeholder="开始日期"
                                    end-placeholder="结束日期" value-format="timestamp" clearable :editable="false" />
                            </el-form-item>
                        </el-col>
                    </template>
                    <el-col :span="6">
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
                            <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
                            <el-button type="text" icon="el-icon-arrow-down" @click="showAll = true"
                                v-if="!showAll">展开</el-button>
                            <el-button type="text" icon="el-icon-arrow-up" @click="showAll = false" v-else>收起</el-button>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-row>
            <div class="SHZY-common-layout-main SHZY-flex-main">
                <div class="SHZY-common-head">
                    <div>
                        <el-radio-group v-model="query.type" @input="initData" >
                            <el-radio-button label="sync">同步</el-radio-button>
                            <el-radio-button label="async">异步</el-radio-button>
                            <el-radio-button label="time">定时</el-radio-button>
                        </el-radio-group>
                    </div>
                    <div class="SHZY-common-head-right">
                        <el-tooltip effect="dark" content="刷新" placement="top">
                            <el-link icon="icon-ym icon-ym-Refresh SHZY-common-head-icon" :underline="false"
                                @click="reset()" />
                        </el-tooltip>
                    </div>
                </div>
                <SHZY-table v-loading="listLoading" :data="list" custom-column>
                    <el-table-column label="创建时间" prop="creatorTime" width="135" align="left">
                        <template slot-scope="scope">{{ scope.row.creatorTime | toDate("yyyy-MM-dd HH:mm:ss") }}</template>
                    </el-table-column>
                    <el-table-column label="状态" prop="status" width="100" align="left">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.status == -1">处理中</el-tag>
                            <el-tag v-if="scope.row.status == 0" type="info">待处理</el-tag>
                            <el-tag v-if="scope.row.status == 1" type="success">处理成功</el-tag>
                            <el-tag v-if="scope.row.status == 2" type="danger">处理异常</el-tag>
                            <el-tag v-if="scope.row.status == 3" type="warning">已关闭</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="处理结果信息" prop="resultMsg" :show-overflow-tooltip="true" width="120" align="left">
                    </el-table-column>
                    <el-table-column label="编码" prop="enCode" align="left">
                    </el-table-column>
                    <el-table-column label="描述" prop="fullName" :show-overflow-tooltip="true" width="120" align="left">
                    </el-table-column>
                    <el-table-column label="执行接口调用时间" prop="execStartTime" width="135" align="left">
                        <template slot-scope="scope">{{ scope.row.execStartTime | toDate("yyyy-MM-dd HH:mm:ss")
                        }}</template>
                    </el-table-column>
                    <el-table-column label="执行接口请求参数" prop="execRequest" :show-overflow-tooltip="true" width="135"
                        align="left">
                        <template slot-scope="scope">
                            <el-button icon="el-icon-search"
                                @click="opendParameters(scope.row.id, 'execRequest', '执行接口请求参数')">查看</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="执行接口返回时间" prop="execEndTime" width="135" align="left">
                        <template slot-scope="scope">{{ scope.row.execEndTime | toDate("yyyy-MM-dd HH:mm:ss") }}</template>
                    </el-table-column>
                    <el-table-column label="执行接口返回参数" prop="execResponse" :show-overflow-tooltip="true" width="135"
                        align="left">
                        <template slot-scope="scope">
                            <el-button icon="el-icon-search"
                                @click="opendParameters(scope.row.id, 'execResponse', '执行接口返回参数')">查看</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="发送接口调用时间" prop="sendStartTime" width="135" align="left">
                        <template slot-scope="scope">{{ scope.row.sendStartTime | toDate("yyyy-MM-dd HH:mm:ss")
                        }}</template>
                    </el-table-column>
                    <el-table-column label="发送接口请求参数" prop="sendRequest" :show-overflow-tooltip="true" width="120"
                        align="left">
                        <template slot-scope="scope">
                            <el-button icon="el-icon-search"
                                @click="opendParameters(scope.row.id, 'sendRequest', '发送接口请求参数')">查看</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="发送接口返回时间" prop="sendEndTime" width="135" align="left">
                        <template slot-scope="scope">{{ scope.row.sendEndTime | toDate("yyyy-MM-dd HH:mm:ss") }}</template>
                    </el-table-column>
                    <el-table-column label="发送接口返回参数" prop="sendResponse" :show-overflow-tooltip="true" width="120"
                        align="left">
                        <template slot-scope="scope">
                            <el-button icon="el-icon-search"
                                @click="opendParameters(scope.row.id, 'sendResponse', '发送接口返回参数')">查看</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="进入处理函数时间" prop="startTime" width="135" align="left">
                        <template slot-scope="scope">{{ scope.row.startTime | toDate("yyyy-MM-dd HH:mm:ss") }}</template>
                    </el-table-column>
                    <el-table-column label="离开处理函数时间" prop="endTime" width="135" align="left">
                        <template slot-scope="scope">{{ scope.row.endTime | toDate("yyyy-MM-dd HH:mm:ss") }}</template>
                    </el-table-column>
                    <el-table-column label="处理时长" prop="timeCost" align="left">
                    </el-table-column>
                    <el-table-column label="运行次数" prop="runCount" align="left">
                    </el-table-column>
                    <el-table-column label="执行接口" prop="execInterfaceId" align="left">
                    </el-table-column>
                    <el-table-column label="异步处理" prop="asyncFlag" align="left">
                        <template slot-scope="scope">
                            <el-tag :type="scope.row.asyncFlag == 'Y' ? '' : 'info'" disable-transitions>
                                {{ scope.row.asyncFlag == 'Y' ? '是' : '否' }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="异常重试次数" prop="retryCount" width="120" align="left">
                    </el-table-column>
                    <el-table-column label="定时接口" prop="cronJobFlag" align="left">
                        <template slot-scope="scope">
                            <el-tag :type="scope.row.cronJobFlag == 'Y' ? '' : 'info'" disable-transitions>
                                {{ scope.row.cronJobFlag == 'Y' ? '是' : '否' }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="发送接口" prop="sendInterfaceId" align="left">
                    </el-table-column>
                    <el-table-column label="Cron表达式" prop="cron" width="120" align="left">
                    </el-table-column>
                    <el-table-column label="执行方式" prop="executeMethod" align="left">
                    </el-table-column>
                    <!-- <el-table-column label="缓存" prop="cacheFlag" align="left">
                        <template slot-scope="scope">
                            <el-tag :type="scope.row.cacheFlag == 'Y' ? '' : 'info'" disable-transitions>
                                {{ scope.row.cacheFlag == 'Y' ? '是' : '否' }}</el-tag>
                        </template>
                    </el-table-column> -->
                </SHZY-table>
                <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize"
                    @pagination="initData" />
            </div>
        </div>
        <Form v-show="formVisible" ref="Form" @close="formVisible = false" />
    </div>
</template>
<script>
import { getInterfaceLogList } from '@/api/system/interface/log'
import Form from './Form'
export default {
    components: { Form },
    name: 'system-interfaceLog',
    data() {
        return {
            showAll: false,
            query: {
                type: "sync",
                enCode: "",
                fullName: "",
                status: "",
                creatorTime: [],
                execEndTime: [],
                sendStartTime: [],
                startTime: []
            },
            list: [],
            listLoading: true,
            multipleSelection: [],
            total: 0,
            listQuery: {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "",
            },
            formVisible: false,
            exportBoxVisible: false,
            columnList: [
                { prop: 'enCode', label: '编码' },
                { prop: 'fullName', label: '描述' },
                { prop: 'execInterfaceId', label: '执行接口ID' },
                { prop: 'asyncFlag', label: '异步处理' },
                { prop: 'retryCount', label: '异常重试次数' },
                { prop: 'cronJobFlag', label: '定时接口' },
                { prop: 'sendInterfaceId', label: '发送接口ID' },
                { prop: 'cron', label: 'Cron表达式' },
                { prop: 'executeMethod', label: '执行方式' },
                { prop: 'cacheFlag', label: '缓存' },
                { prop: 'startTime', label: '进入处理函数时间' },
                { prop: 'endTime', label: '离开处理函数时间' },
                { prop: 'execStartTime', label: '执行接口调用时间' },
                { prop: 'execEndTime', label: '执行接口返回时间' },
                { prop: 'execRequest', label: '执行接口请求参数' },
                { prop: 'execResponse', label: '执行接口返回参数' },
                { prop: 'sendStartTime', label: '发送接口调用时间' },
                { prop: 'sendEndTime', label: '发送接口返回时间' },
                { prop: 'sendRequest', label: '发送接口请求参数' },
                { prop: 'sendResponse', label: '发送接口返回参数' },
                { prop: 'timeCost', label: '处理时长' },
                { prop: 'runCount', label: '运行次数' },
                { prop: 'status', label: '状态' },
                { prop: 'resultMsg', label: '处理结果信息' },
                { prop: 'creatorTime', label: '创建时间' },
            ],
            execInterfaceIdOptions: [{ 'fullName': "选项一", 'id': "1" }, { 'fullName': "选项二", 'id': "2" }],
            asyncFlagOptions: [{ 'fullName': "是", 'id': "Y" }, { 'fullName': "否", 'id': "N" }],
            cronJobFlagOptions: [{ 'fullName': "是", 'id': "Y" }, { 'fullName': "否", 'id': "N" }],
            sendInterfaceIdOptions: [{ 'fullName': "选项一", 'id': "1" }, { 'fullName': "选项二", 'id': "2" }],
            executeMethodOptions: [{ 'fullName': "并行", 'id': "Parallel" }, { 'fullName': "串行", 'id': "Serial" }],
            cacheFlagOptions: [{ 'fullName': "是", 'id': "Y" }, { 'fullName': "否", 'id': "N" }],
        }
    },
    computed: {
        menuId() {
            return this.$route.meta.modelId || ''
        }
    },
    created() {
        this.initData()
    },
    methods: {
        initData() {
            this.listLoading = true;
            let _query = {
                ...this.listQuery,
                ...this.query,
                menuId: this.menuId,
            };
            let query = {}
            for (let key in _query) {
                if (Array.isArray(_query[key])) {
                    query[key] = _query[key].join()
                } else {
                    query[key] = _query[key]
                }
            }
            getInterfaceLogList(query).then(res => {
                this.list = res.data.list
                this.total = res.data.pagination.total
                this.listLoading = false
            })
        },
        search() {
            this.listQuery = {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "creatorTime",
            }
            this.initData()
        },
        opendParameters(id, type, title) {
            this.formVisible = true
            this.$nextTick(() => {
                this.$refs.Form.init(id, type, title)
            })

        },
        reset() {
            this.query = {
                type: "sync",
                enCode: "",
                fullName: "",
                status: "",
                creatorTime: [],
                execEndTime: [],
                sendStartTime: [],
                startTime: []
            }

            this.listQuery = {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "creatorTime",
            }
            this.initData()
        }
    }
}
</script>